#ifndef __LUASTATE_H__
#define __LUASTATE_H__

#include <string>
#include <vector>
struct lua_State;
namespace LuaPerform
{
	class LUAPERFORM_API LuaState
	{
	public:
		LuaState(void);
		~LuaState(void);

		enum LuaLib
		{
			IO_Lib		=	1,
			Table_Lib	=	2,
			Math_Lib	=	4,
			System_Lib	=	8,
			String_Lib	=	16,
			All_Lib		=	IO_Lib | Table_Lib | Math_Lib | System_Lib | String_Lib
		};

	public:
		void OpenLuaLib(LuaLib libType);
		void RegistCFunction(std::string name, lua_CFunction func);

		/*simple example
		std::string script = "return "HelloWorld"";
		LuaState state;
		state.OpenLuaLib(All_Lib);
		int index = state.Comply(script);
		state.RegisterRefAt(index);
		std::string result = "";
		bool xx = state.Execute(index, result);*/
		int Comply(std::string& script);
		bool Execute(std::string& result);
		void RegisterRefAt(int index);
		void RegisterUnref(int index);
		std::string LastError() const;

	public:
		typedef void(*LuaCFunction)(lua_State* L);
		bool LoadCFunctionDLL(std::string& path);

	private:
		lua_State*			m_L;
		std::string			m_LastError;
		std::vector<void*>	m_CFunctionDLLs;
	};
}
#endif